package com.ubisolv.vmakeup.adapter;

import com.ubisolv.vmakeup.R;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.ubisolv.vmakeup.data.StyleColorData;

public class ColorAdapter extends BaseAdapter {
	private int mMakeupId =	-1;
	private int[] mColor =	null;
	
	public ColorAdapter() {
		super();
	}
	
	public ColorAdapter(int id) {
		super();
		mMakeupId =	id;
		mColor =	StyleColorData.getColor(mMakeupId);
	}
	
	public void setMakeupId(int id) {
		mMakeupId =	id;
		mColor =	StyleColorData.getColor(mMakeupId);
		
		notifyDataSetChanged();
	}
	
    @Override
    public int getCount() {
    	int result =	0;
    	
    	if (mColor != null) {
    		result =	mColor.length;
    	}
    	
        return result;
    }

    @Override
    public Object getItem(int position) {
    	int result =	-1;
    	
    	if (mColor != null && position < mColor.length) {
    		result =	mColor[position];
    	}
    	
    	return result;
    }

    @Override
    public long getItemId(int position) {
    	return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View retval = 			LayoutInflater.from(parent.getContext()).inflate(R.layout.viewitem_color_layout, null);
        
        ImageView imageView = 	(ImageView)retval.findViewById(R.id.image);
        
        if (position < mColor.length) {
        	imageView.setImageResource(mColor[position]);
        }
        
        return retval;
    }
}
